//
//  paySuccessViewController.m
//  BeautyPicture
//
//  Created by 沈振邦 on 15/9/2.
//  Copyright (c) 2015年 szb. All rights reserved.
//  支付成功后弹出的界面

#import "paySuccessViewController.h"
#import "headPromptView.h"
#import "BPshareSdkView.h"
#import <ShareSDK/ShareSDK.h>
#import "MBProgressHUD+MJ.h"

#define btnColor  BPColor(31, 34, 50)

@interface paySuccessViewController ()<BPShareDelegate>

@end

@implementation paySuccessViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:self.view.bounds];
    image.image = [UIImage resizedImage:@"BPShareBgImage"];
    [self.view addSubview:image];
    
    //设置头部提示view
    headPromptView *headView = [[headPromptView alloc] init];
    CGFloat imageW = 30.0f;
    headView.promptImage.image = [UIImage imageNamed:@"successImage"];
    headView.promptImage.frame = CGRectMake(0, 0, imageW, imageW);
    
    headView.promptText.text = @"恭喜 , 支付已成功 !";
    UIFont *textfont = [UIFont fontWithName:@"HelveticaNeue" size:18.0f];
    headView.promptText.font = textfont;
    CGSize labelS = [headView.promptText.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:headView.promptText.font,NSFontAttributeName, nil]];
    CGFloat labelY = (30.0f - labelS.height) / 2.0;
    headView.promptText.frame = (CGRect){{imageW + 20.0f,labelY},labelS};
    
    CGFloat viewW = CGRectGetMaxX(headView.promptText.frame);
    CGFloat viewX = (BPScreenW - viewW) / 2.0;
    headView.frame = CGRectMake(viewX, BPScreenNavY + 50.0f, viewW, imageW);
    [self.view addSubview:headView];
    
    UIButton *continueMakeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    CGFloat btnX = 80.0f;
    continueMakeBtn.frame = CGRectMake(btnX, headView.y + 40.0f +headView.height, BPScreenW - 2 *btnX, 50.0f);
    [continueMakeBtn addTarget:self action:@selector(continueMake) forControlEvents:UIControlEventTouchUpInside];
    [self setButton:continueMakeBtn addButtonTitle:@"继续制作"];
    
    UIButton *lookOrderBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    lookOrderBtn.frame = CGRectMake(btnX, continueMakeBtn.y + 15.0f +continueMakeBtn.height, BPScreenW - 2 *btnX, 50.0f);
    [lookOrderBtn addTarget:self action:@selector(lookOrder) forControlEvents:UIControlEventTouchUpInside];
    [self setButton:lookOrderBtn addButtonTitle:@"查看订单"];
    lookOrderBtn.backgroundColor = btnColor;
    
    UILabel *detailLabel = [[UILabel alloc] init];
    detailLabel.numberOfLines = 0;
    NSString *text = @"分享有机会赚代金券哦 !";
    detailLabel.frame = CGRectMake(20.0f, lookOrderBtn.y + lookOrderBtn.height, BPScreenW - 40.0, 100);
    detailLabel.text = text;
    detailLabel.textColor = btnColor;
    detailLabel.textAlignment = NSTextAlignmentCenter;
    detailLabel.font = [UIFont systemFontOfSize:14.0f];
    detailLabel.alpha = 0.8;
    [self.view addSubview:detailLabel];
    
    CGFloat shareY = CGRectGetMaxY(detailLabel.frame);
    CGFloat shareX = 25.0f;
    BPshareSdkView *shareView = [[BPshareSdkView alloc] initWithFrame:CGRectMake(shareX, shareY, BPScreenW - shareX * 2.0, 70.0f)];
    shareView.delegate = self;
    [self.view addSubview:shareView];
    
}

- (void)continueMake
{

}

- (void)lookOrder
{

}

- (void)shareToolView:(BPshareSdkView *)shareView didClickButton:(BPShareButtonType)buttonType
{
    switch (buttonType) {
        case BPShareToWeibo:
            [self shareToApp:[shareView viewWithTag:buttonType] shareType:ShareTypeSinaWeibo];
            break;
        case BPShareToWX:
            
            break;
        case BPShareToQQ:
            [self shareToApp:[shareView viewWithTag:buttonType] shareType:ShareTypeQQ];
            
            break;
        case BPShareToBP:
            [self shareToBP];
            break;
        default:
            break;
    }
}

- (void)shareToApp:(id)sender shareType:(ShareType)type
{
    //NSUserDefaults.
    NSString *imagePath = [[NSBundle mainBundle] pathForResource:@"" ofType:@""];
    id<ISSContent> publishContent = [ShareSDK content:@"aaa"
                                       defaultContent:@"http://www.len.so"
                                                image:[ShareSDK imageWithPath:imagePath]
                                                title:@"分享"
                                                  url:@"http://www.len.so"
                                          description:NSLocalizedString(@"TEXT_TEST_MSG", @"这是一条测试信息")
                                            mediaType:SSPublishContentMediaTypeNews];
    
    
    //创建弹出菜单容器
    id<ISSContainer> container = [ShareSDK container];
    [container setIPadContainerWithView:sender arrowDirect:UIPopoverArrowDirectionUp];
    
    id<ISSAuthOptions> authOptions = [ShareSDK authOptionsWithAutoAuth:YES
                                                         allowCallback:YES
                                                         authViewStyle:SSAuthViewStyleFullScreenPopup
                                                          viewDelegate:nil
                                               authManagerViewDelegate:nil];
    
    id<ISSShareOptions> shareOptions = [ShareSDK defaultShareOptionsWithTitle:nil
                                                              oneKeyShareList:[NSArray defaultOneKeyShareList]
                                                               qqButtonHidden:NO
                                                        wxSessionButtonHidden:NO
                                                       wxTimelineButtonHidden:NO
                                                         showKeyboardOnAppear:NO
                                                            shareViewDelegate:nil
                                                          friendsViewDelegate:nil                                                     picViewerViewDelegate:nil];
    
    
    //分享类型
    [ShareSDK showShareViewWithType:type
                          container:container
                            content:publishContent
                      statusBarTips:YES
                        authOptions:authOptions
                       shareOptions:shareOptions
                             result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
                                 
                                 if (state == SSPublishContentStateSuccess)
                                 {
                                     [MBProgressHUD showSuccess:@"发表成功"];
                                 }
                                 else if (state == SSPublishContentStateFail)
                                 {
                                     [MBProgressHUD showError:@"发表失败"];
                                 }
                             }];
}


- (void)shareToBP
{
    
}


- (void)setButton:(UIButton *)button addButtonTitle:(NSString *)title
{
    [button.layer setMasksToBounds:YES];
    [button.layer setCornerRadius:25.0f];
    button.backgroundColor = BPGlobaThemeColor;
    [button setTitle:title forState:UIControlStateNormal];
    [button setTintColor:[UIColor whiteColor]];
    [self.view addSubview:button];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
